import com.alibaba.fastjson.{JSONObject, JSONPObject}
import com.king.common.GmallConfig

/**
 * @Author: KingWang
 * @Date: 2022/1/11  
 * @Desc:
 **/
object TestDemo {

  def main(args: Array[String]): Unit = {

    val sinkTable = "test"
    val sinkColumns = "id,name,sex"
    val sinkPk = "id"
    val begin_sql =s"""
                      |create table if not exists ${GmallConfig.HBASE_SCHEMA}.$sinkTable (
                      |""".stripMargin
    val columns = sinkColumns.split(",")
      .map(f=> if(f.equals(sinkPk)) f.concat(" varchar primary key") else f.concat(" varchar ") )
      .mkString(",")
      .concat(")")
    val create_table_sql = begin_sql+columns
    println(create_table_sql)


    val fields = sinkColumns.split(",")
    val obj = new JSONObject()
    obj.put("id",1)
    obj.put("name","king")
    obj.put("sex","nan")
    obj.put("age",20)

    val newObj = new JSONObject()

    fields.map{x=>
     newObj.put(x,obj.get(x))
    }
    println(obj.toJSONString)
    println(newObj.toJSONString)

  }

}
